package com.dq.controller.user;

import com.dq.controller.in.EvaluateQuery;
import com.dq.controller.in.EvaluateRecordQuery;
import com.dq.domain.evaluation.EvaluationRecord;
import com.dq.domain.evaluation.EvaluationRecordTemplate;
import com.dq.exception.customException.AdminException;
import com.dq.service.AllService;
import com.dq.vo.Vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author luchangtong
 * @Date 2020/5/21 14:07
 */
@Api(description = "店铺评价管理")
@RestController
@RequestMapping("sys/boss/evaluationRecord/")
public class SysEvaluationRecordController extends AllService {

    @ApiOperation("列表")
    @PostMapping("list")
    public Vo list(@RequestBody EvaluateRecordQuery evaluateQuery) throws AdminException{
        return evaluationRecordService.list(evaluateQuery);
    }

    @ApiOperation("评价详情")
    @GetMapping("/evaluationDetail/{id}")
    public Vo evaluationDetail(@PathVariable Long id)throws AdminException{
        EvaluationRecord evaluationRecord = dao.get(EvaluationRecord.class,id);
        List<EvaluationRecordTemplate> evaluationRecordTemplates = evaluationRecordTemplateRepository.findByEvaluationRecord(evaluationRecord);
        List<EvaluationRecordTemplate.Vo> list = new ArrayList<>();
        evaluationRecordTemplates.forEach(evaluationRecordTemplate -> {
            EvaluationRecordTemplate.Vo vo = (EvaluationRecordTemplate.Vo) evaluationRecordTemplate.toVO();
            list.add(vo);
        });
        return new Vo(list);
    }
}
